//
//  GWYForWardTableViewCell.swift
//  swift-GWYWeiBo
//
//  Created by x on 2017/6/2.
//  Copyright © 2017年 HLB. All rights reserved.
//

import UIKit

class GWYForWardTableViewCell: GWYHomeSatuesTableViewCell {

    //子类重写父类的didSet方法并不会覆盖父类的操作
    //只要在重写方法中做你想做的事情即可
    //注意点: 如果父类是didSet那么子类也只能重写didSet 要和父类保持一致
    override var modle:Status? {
        didSet {
            let name = modle?.retweeted_status?.user?.name ?? ""
            let text = modle?.retweeted_status?.text ?? ""
            
            forWardLable.text = name + ": " + text
        }
    }
    
    
    //转发微博 增加一个蒙版  转发的微博内容
    
    override func setupUI() {
        //继承父类父方法
        super.setupUI()
        
        //1.添加子控件
        contentView.insertSubview(forWardBtu, belowSubview: pictureView)
        contentView.insertSubview(forWardLable, aboveSubview: forWardBtu)
        //2.布局子控件
        contentView.addConstraint(NSLayoutConstraint.init(item: forWardBtu, attribute: NSLayoutAttribute.left, relatedBy: NSLayoutRelation.equal, toItem: u_wb_contentLable, attribute: NSLayoutAttribute.left, multiplier: 1.0, constant: -10))
        contentView.addConstraint(NSLayoutConstraint.init(item: forWardBtu, attribute: NSLayoutAttribute.top, relatedBy: NSLayoutRelation.equal, toItem: u_wb_contentLable, attribute: NSLayoutAttribute.bottom, multiplier: 1.0, constant: 10))
        contentView.addConstraint(NSLayoutConstraint.init(item: forWardBtu, attribute: NSLayoutAttribute.bottom, relatedBy: NSLayoutRelation.equal, toItem: footView, attribute: NSLayoutAttribute.top, multiplier: 1.0, constant: 0))
        contentView.addConstraint(NSLayoutConstraint.init(item: forWardBtu, attribute: NSLayoutAttribute.right, relatedBy: NSLayoutRelation.equal, toItem: footView, attribute: NSLayoutAttribute.right, multiplier: 1.0, constant: 0));
        
        contentView.addConstraint(NSLayoutConstraint.init(item: forWardLable, attribute: NSLayoutAttribute.left, relatedBy: NSLayoutRelation.equal, toItem: forWardBtu, attribute: NSLayoutAttribute.left, multiplier: 1.0, constant: 10))
        contentView.addConstraint(NSLayoutConstraint.init(item: forWardLable, attribute: NSLayoutAttribute.top, relatedBy: NSLayoutRelation.equal, toItem: forWardBtu, attribute: NSLayoutAttribute.top, multiplier: 1.0, constant: 0))
        //2.3重新调整转发转发配图的约束
        contentView.addConstraint(NSLayoutConstraint.init(item: pictureView, attribute: NSLayoutAttribute.left, relatedBy: NSLayoutRelation.equal, toItem: forWardLable, attribute: NSLayoutAttribute.left, multiplier: 1.0, constant: 0))
        pictureTopCons = NSLayoutConstraint.init(item: pictureView, attribute: NSLayoutAttribute.top, relatedBy: NSLayoutRelation.equal, toItem: forWardLable, attribute: NSLayoutAttribute.bottom, multiplier: 1.0, constant: 10)
        contentView.addConstraint(pictureTopCons!)        
    }
    
    //MARK: -- 懒加载
    
    /// 转发微博正文
    private lazy var forWardLable = { ()-> UILabel in
        let tt = UILabel.creatLbale(color: UIColor.darkGray, fontSize: 15)
        tt.numberOfLines = 0
        tt.preferredMaxLayoutWidth = WIDTH - 20
        return tt
    }()

    /// 背景按钮
    private lazy var forWardBtu: UIButton = { ()-> UIButton in
        let btu = UIButton()
        btu.translatesAutoresizingMaskIntoConstraints = false
        btu.backgroundColor = UIColor.init(white: 0.9, alpha: 1.0)
        return btu
    }()
}
